var utils=require('../../modules/utils');

var Resize=function(cf) {
	var bar=cf.bar;
	var tar=cf.tar;
	var onResizing=cf.onResizing;
	var onResized=cf.onResized;
	if (!!!bar) return;
	
	function msDown(e){
		var pos={
			x:e.clientX,
			y:e.clientY
		}
		var offset={
			left:tar.offsetLeft,
			top:tar.offsetTop,
			width:tar.offsetWidth,
			height:tar.offsetHeight
		}
		document.onmousemove=function(e){
			var e1=e||window.event;
			e1.preventDefault?e1.preventDefault():e1.cancelBubble=true;
			var _pos={
				w:e1.clientX-pos.x,
				h:e1.clientY-pos.y
			}
			onResizing&&onResizing.call({bar:bar,tar:tar},_pos,offset);
		}
		document.onmouseup=function(e1){
			document.onmousemove=null;
			document.onmouseup=null;
			onResized&&onResized.call(bar);
		}
	}
	utils.DOMEvent.add(bar,'mousedown',msDown);
}

module.exports = Resize;